package com.whmnx.main.ui.model;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.whmnx.base.constants.EventConstants;

import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.bus.RxBus;
import me.goldze.mvvmhabit.bus.RxSubscriptions;

/**
 * author : huang
 * date   : 2020/11/5 0005 15:13
 * version: 1.0
 */
public class ShouModel extends BaseViewModel {


    public ObservableField<String> tv = new ObservableField<>("");
    Disposable subscribe;
    public ShouModel(@NonNull Application application) {
        super(application);
        initView();
    }


    private void initView() {
        subscribe = RxBus.getDefault().toObservable(String.class)
                .subscribe(new Consumer<String>() {
                    @Override
                    public void accept(String object){
                     if (object.contains(EventConstants.SHOU)){
                         tv.set(object.split("-")[1]);
                        }
                    }
                });
        RxSubscriptions.add(subscribe);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        //解除注册
        RxSubscriptions.remove(subscribe);
    }



}
